package cn.edu.seig.springks.controller;

import cn.edu.seig.springks.pojo.order;
import cn.edu.seig.springks.service.ordersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ordersController类用于处理与订单相关的RESTful API请求
 * 它依赖于ordersService接口的实现来处理具体的业务逻辑
 */
@RestController
@RequestMapping(value ="/api/orders")
public class ordersController {

    @Autowired
    ordersService ordersService;

    /**
     * 获取用户订单信息
     *
     * @param u_id 用户ID，用于查询该用户的订单信息
     * @return 包含订单信息的List，每个订单对象包含订单号，名称，数量，总金额，地址，时间等信息
     */
    @GetMapping(value = "/getOrder/{u_id}")
    public ResponseEntity<List<order>> getOrder(@PathVariable Integer u_id){
        List<order> orders = ordersService.selectOrderByUserId(u_id);
        return ResponseEntity.ok(orders);
    }
}
